<template>
  <div>
    <!-- 搜索 -->
    <!-- 技术报告查询 - 维修工单选择 -->
    <TopFilter :list="topFilterInit" :cols="3" :collapse="collapse" labelWidth="90" @filterChange="changeHandle"></TopFilter>
    <!-- table -->
    <FilterTable height="auto" selectionType="single" ref="table" :columns="columns"
                 :fetchapi="fetchapi"
                 :params="fetchParams"
                 :datakey="'records'"
                 :onColumnsChange="columns => (this.columns = columns)"
                 :onRowSelectChange="selectChange"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right'
      }"
    >
      <multiuse-button type="primary" :click="saveDialog.bind()" :disabled="disableds">添 加</multiuse-button>
      <multiuse-button @click="closeDialog">关 闭</multiuse-button>
    </div>
  </div>
</template>
<script>
import { queryRepairOrderForClaim }  from '@/api/dictionary/index';
import { dictionary } from '@/utils/dictMixin';
import moment from "moment";
export default {
  mixins: [dictionary],
  data() {
    return {
      dataList: [],
      visible: false,
      visibleDrawer: false,
      collapse: false,
      disableds: true,
      infoId: null,
      topFilterInit: this.topFilterInitFun(),
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchapi:queryRepairOrderForClaim,
      // fetchApi: getUser,
      fetchParams: { querFlag: "preAuth", xhrAbort: true }, //ipa 接口
      selectedRows: [] //选中经销商
    };
  },
  created() {
    // this.chuqi();
  },
  methods: {

    //搜索数据
    topFilterInitFun() {
      return [
        { type: 'INPUT', label: '维修工单号', fieldName: 'roNo', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: 'VIN', fieldName: 'vin', placeholder: '请输入', initialValue: '' },
        { type: 'INPUT', label: '车牌号', fieldName: 'license', placeholder: '请输入', initialValue: '' },
        // { type: 'DATE', label: '开单日期', fieldName: 'roCreateTime', placeholder: '请输入', initialValue: '' },

        //{ type: 'RANGE_DATE', label: '维修结算日期', fieldName: 'beginSettleAt|endSettleAt', placeholder: '请输入', initialValue: '' },

        { type: 'INPUT', label: '客户姓名', fieldName: 'ownerName', placeholder: '请输入', initialValue: '' },
        {
          type: 'RANGE_DATE',
          label: '开单日期',
          fieldName: 'createBeginTime|createEndTime',
          initialValue: [
            moment()
              .startOf('month')
              .format('YYYY-MM-DD HH:mm:ss'),
            moment()
              .endOf('month')
              .format('YYYY-MM-DD HH:mm:ss')
          ],
          dateType: 'datetimerange',
          placeholder: '请输入',
          rules: [{ required: true, message: '请选择日期', trigger: 'change' }]
        },
        // { type: 'INPUT', label: '客户电话', fieldName: 'MOBILE', placeholder: '请输入', initialValue: '' },
        // { type: 'SELECT', label: '日期类型', fieldName: 'DATE_TYPE', placeholder: '请输入',initialValue: 'RO_CREATE_DATE',itemList: [{text: '工单开单时间', value: "RO_CREATE_DATE"}, {text: '维修结算时间', value: "BALANCE_TIME"}],
        //   rules: [{ required: true, message: '请选择日期类型', trigger: 'change' }],
        //   change: val => {
        //     if(val){
        //       let list = this.topFilterInit.find(x => x.fieldName === 'DATE_TYPE').itemList;
        //       const tmpValue = list.find(x => x.value === val).value;
        //       this.dateType = tmpValue;
        //
        //     }
        //   }
        //
        // },
        // { type: 'RANGE_DATE', label: '日期', fieldName: 'BEGIN_TIME|END_TIME', placeholder: '请输入', initialValue: '' },
      ];
    },
    //搜索获取数据
    changeHandle(val) {
      this.fetchParams = Object.assign({ querFlag: 1 }, this.fetchParams, val, { xhrAbort: false });

      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        // 维修工单号、VIN、电机号、维修日期、进厂里程
        { title: '工单编号', dataIndex: 'roNo', sorter: true },
        { title: 'VIN', dataIndex: 'vin', sorter: true },
        { title: '客户名称', dataIndex: 'ownerName', sorter: true },
        // { title: '客户电话', dataIndex: 'MOBILE', sorter: true },
        { title: '车牌号', dataIndex: 'license', sorter: true },
        { title: '车型名称', dataIndex: 'modelName', sorter: true },
        {
          title: '维修类型',
          dataIndex: 'repairTypeName',
          sorter: true,
          dictItems:[]
        },
        { title: '开单日期', dataIndex: 'roCreateDate', sorter: true },
        { title: '结算日期', dataIndex: 'balanceTime', sorter: true }
      ];
    },
    //选中
    selectChange(rows) {
      this.selectedRows = rows;
      this.disableds = this.selectedRows.length <= 0;
      console.log(this.selectedRows);
    },
    //保存
    saveDialog() {
      this.selectedRows.map(x => {
        x.roNo = x.roNo;
        x.vin = x.vin;
        x.customerName = x.ownerName;
        x.customerPhone = x.phone;
        x.licenseNo = x.license;
        x.serviceBeginDate = x.roCreateDate;
        x.serviceEndDate = x.completeTime;
        x.serviceName = x.deliverer;
        x.servicePhone = x.delivererMobile;
        x.driveMile = Number(x.inMileage)|| 0;
        x.engineNo = x.engineNo;

      });
      this.$emit('save', this.selectedRows);
    },
    //取消操作
    closeDialog() {
      this.$emit('close', { visible: false, data: this.selectedRows, type: 'close' });
    },
    chooseOrderNo() {
      this.visible = true;
    }
  }
  // mounted() {
  //   this.BaseTable = this.$refs.listModal.$refs.pageTable;
  // }
};
</script>

<style lang="less" scoped></style>
